﻿using MediatR;
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc;
using Traceability.ErrorCode;
using Traceability.Write.Api.Application.Command;

namespace Traceability.Write.Api.Controllers
{
    [Route("api/[controller]/[action]")]
    [ApiController]
    public class MainController : ControllerBase
    {
        private readonly IMediator mediator;

        public MainController(IMediator mediator)
        {
            this.mediator = mediator;
        }

        /// <summary>
        /// 添加图片表处理
        /// </summary>
        /// <param name="request"></param>
        /// <returns></returns>
        [HttpPost]
        public async Task<ApiResult<int>> Handle(AddImagerCommand request)
        {
            try
            {
                return await mediator.Send(request);
            }
            catch (Exception)
            {

                throw;
            }
        }

        /// <summary>
        /// 删除产品检验图片
        /// </summary>
        /// <param name="request"></param>
        /// <returns></returns>
        [HttpDelete]
        public Task<ApiResult<int>> Handle([FromQuery] DelImageCommand request)
        {
            try
            {
                return mediator.Send(request);
            }
            catch (Exception)
            {

                throw;
            }
        }


        /// <summary>
        /// 添加养殖信息操作
        /// </summary>
        /// <param name="request"></param>
        /// <returns></returns>
        [HttpPut]
        public Task<ApiResult<int>> AddCultivation(AddCultivationCommand request)
        {
            try
            {
                return mediator.Send(request);
            }
            catch (Exception)
            {

                throw;
            }
        }

        /// <summary>
        /// 添加免疫信息操作
        /// </summary>
        /// <param name="request"></param>
        /// <returns></returns>
        [HttpPost]
        public async Task<ApiResult<int>> AddImmunity(AddImmunityCommand request)
        {
            try
            {
                return await mediator.Send(request);
            }
            catch (Exception)
            {

                throw;
            }
        }

        /// <summary>
        /// 删除免疫信息
        /// </summary>
        /// <param name="request"></param>
        /// <returns></returns>
        [HttpDelete]
        public Task<ApiResult<int>> DelImmunity([FromQuery] DelImmunityCommand request)
        {
            try
            {
                return mediator.Send(request);
            }
            catch (Exception)
            {

                throw;
            }
        }

        /// <summary>
        /// 修改免疫信息操作
        /// </summary>
        /// <param name="request"></param>
        /// <returns></returns>
        [HttpPut]
        public async Task<ApiResult<int>> UpdateImmunityHander(UpdateImmunityCommand request)
        {
            try
            {
                return await mediator.Send(request);
            }
            catch (Exception)
            {

                throw;
            }
        }

        /// <summary>
        /// 添加养殖企业信息操作
        /// </summary>
        /// <param name="request"></param>
        /// <returns></returns>
        [HttpPut]
        public async Task<ApiResult<int>> AddEnterprise(AddEnterpriseCommand request)
        {
            try
            {
                return await mediator.Send(request);
            }
            catch (Exception)
            {

                throw;
            }
        }

        /// <summary>
        /// 添加屠宰信息操作
        /// </summary>
        /// <param name="request"></param>
        /// <returns></returns>
        [HttpPut]
        public async Task<ApiResult<int>> AddSlaughter(AddSlaughterCommand request)
        {
            try
            {
                return await mediator.Send(request);
            }
            catch (Exception)
            {

                throw;
            }
        }

        /// <summary>
        /// 添加企业
        /// </summary>
        /// <param name="request"></param>
        /// <returns></returns>
        [HttpPost]
        public async Task<ApiResult<int>> UpdateEnterprise(UpdateEnterpriseCommand request)
        {
            try
            {
                return await mediator.Send(request);
            }
            catch (Exception)
            {

                throw;
            }
        }

        /// <summary>
        /// 修改深加工企业
        /// </summary>
        /// <param name="request"></param>
        /// <returns></returns>
        [HttpPut]
        public async Task<ApiResult<int>> S_UpdateEnterpriseHander([FromBody] S_UpdateEnterpriseCommand request)
        {
            try
            {
                return await mediator.Send(request);
            }
            catch (Exception)
            {

                throw;
            }
        }

        /// <summary>
        /// 修改供应商操作
        /// </summary>
        /// <param name="request"></param>
        /// <returns></returns>
        [HttpPut]
        public async Task<ApiResult<int>> UpdateVendor([FromBody]AddVendorCommand request)
        {
            try
            {
                return await mediator.Send(request);
            }
            catch (Exception)
            {

                throw;
            }
        }
    }
}
